package com.alamiya.security.service.impl;

import com.alamiya.security.entity.PublicUserRoleRelation;
import com.alamiya.security.mapper.PublicUserRoleRelationMapper;
import com.alamiya.security.service.IPublicUserRoleRelationService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hehaoqi
 * @since 2021-02-02
 */
@Service
public class PublicUserRoleRelationServiceImpl extends ServiceImpl<PublicUserRoleRelationMapper, PublicUserRoleRelation> implements IPublicUserRoleRelationService {

    @Override
    public List<String> listRoleIdsByUserId(String userId) {
        List<String> roleIds = list(new LambdaQueryWrapper<PublicUserRoleRelation>()
                .eq(PublicUserRoleRelation::getUserId, userId))
                .stream()
                .map(PublicUserRoleRelation::getRoleId)
                .collect(Collectors.toList());
        return Objects.isNull(roleIds) ? Collections.EMPTY_LIST : roleIds;
    }
}
